package com.xzl.time.controller;

import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.github.pagehelper.PageInfo;
import com.xzl.time.pojo.Notice;
import com.xzl.time.service.INoticeService;
import com.xzl.time.utils.MyEnum;
import com.xzl.tool.util.MyException;
import com.xzl.tool.util.RespBean;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


@Api(tags = "消息管理层")
@RestController
@RequestMapping("/notice")
public class NoticeController {
    @Autowired
    private INoticeService noticeService;

    @GetMapping("/getThumbsUpNotice")
    @ApiOperation("查询点赞消息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum",value = "页数",required = true,paramType = "query"),
            @ApiImplicitParam(name = "pageSize",value = "条数",required = true,paramType = "query"),
            @ApiImplicitParam(name = "userName",value = "当前用户名",required = true,paramType = "query")
    })
    public RespBean getThumbsUpNotice(int pageNum,int pageSize,String userName){
        if (StringUtils.isBlank(userName)) throw new MyException(500,"参数异常！");
        PageInfo<Notice> notices = noticeService
                .getNoticeByTypeAndReceiverId(pageNum,pageSize, MyEnum.ARTICLE_THUMBSUP.getValue(),userName);
        return RespBean.success(notices);
    }
    @GetMapping("/getFollowNotice")
    @ApiOperation("查询关注消息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum",value = "页数",required = true,paramType = "query"),
            @ApiImplicitParam(name = "pageSize",value = "条数",required = true,paramType = "query"),
            @ApiImplicitParam(name = "userName",value = "当前用户名",required = true,paramType = "query")
    })
    public RespBean getFollowNotice(int pageNum,int pageSize,String userName){
        if (StringUtils.isBlank(userName)) throw new MyException(500,"参数异常！");
        PageInfo<Notice> notices = noticeService
                .getNoticeByTypeAndReceiverId(pageNum,pageSize, MyEnum.ARTICLE_SUBSCRIBE_.getValue(),userName);
        return RespBean.success(notices);
    }
    @GetMapping("/getCommentNotice")
    @ApiOperation("查询评论消息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum",value = "页数",required = true,paramType = "query"),
            @ApiImplicitParam(name = "pageSize",value = "条数",required = true,paramType = "query"),
            @ApiImplicitParam(name = "userName",value = "当前用户名",required = true,paramType = "query")
    })
    public RespBean getCommentNotice(int pageNum,int pageSize,String userName){
        if (StringUtils.isBlank(userName)) throw new MyException(500,"参数异常！");
        PageInfo<Notice> notices = noticeService
                .getNoticeByTypeAndReceiverId(pageNum,pageSize, MyEnum.ARTICLE_COMMENT_.getValue(),userName);
        return RespBean.success(notices);
    }
}
